package com.myjpa.service;

import com.myjpa.common.criteria.JacksonCriteria;
import com.myjpa.common.web.MapResponse;
import com.myjpa.common.web.PagedResponse;
import com.myjpa.entity.Order;
import com.myjpa.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @author: yaoll
 * @date: 2020-09-04
 * @verison: 1.0
 */
@Service
public class OrderService {

	@Autowired
	private OrderRepository repository;

	public PagedResponse<Order> query(JacksonCriteria criteria) {
		return null;
	}

	@Transactional
	public MapResponse create(Order order) {
		repository.save(order);
		MapResponse resp = new MapResponse();
		resp.add("id", order.getId());
		return resp;
	}

	public MapResponse update(Order order) {
		repository.save(order);
		MapResponse resp = new MapResponse();
		resp.add("id", order.getId());
		return resp;
	}

	public MapResponse delete(Order order) {
		repository.deleteById(order.getId());
		return new MapResponse();
	}
}
